/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Diagnostico_View_Add.java
 *
 * Created on 14/08/2012, 11:43:06 PM
 */
package v;

import beans.DiscapacidadTratamiento;
import beans.MedicamentoDiscapacidad;
import beans.TerapiaDiscapacidad;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import tools.DatosComboBox;
import v.Evaluacion_View_Add.SetTerapiasMedicamentos;
import v.VentanaNuevosElementos.Listener;

/**
 *
 * @author Usuario
 */
public class NuevasTerMed_UI extends javax.swing.JPanel {
    
    
    private TableModel terapiaModel;
    private TableModel medicamentoModel;
    
    //
    private String[] columnTerapia = {"Terapia", "Intensidad", "Cantidad", "Inicio"};
    private String[] columnMedic = {"Medicamento", "Dosis", "Uso", "Inicio"};
    
    private DatosComboBox cbx = new DatosComboBox();
    
    private Medicamento_View_Add medicamentoPanel;
    private Terapia_View_Add terapiaPanel;
    
    private Map<Integer, TerapiaDiscapacidad> terapiasTabla = 
            new HashMap<Integer, TerapiaDiscapacidad>();
    private Map<Integer, MedicamentoDiscapacidad> medicamentosTabla =
            new HashMap<Integer, MedicamentoDiscapacidad>();
    
    private SetTerapiasMedicamentos elemRecibidos;
    private SetTerapiasMedicamentos elemLocales = new SetTerapiasMedicamentos();
    
    private VentanaNuevosElementos.Listener listener;
    
    /** Creates new form Diagnostico_View_Add */
    public NuevasTerMed_UI(SetTerapiasMedicamentos nuevosElem) {
        initComponents();
        
        elemRecibidos = nuevosElem;
        copiarElem(elemRecibidos, elemLocales);
        
        setComponents();
        
        setListeners();
        
        setTerapiaModel(elemLocales.nuevasTer);
        setMedicamentosModel(elemLocales.nuevosMedic);
        
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel7 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        terapia_View_Add1 = new v.Terapia_View_Add();
        botonAgregarTer = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaTerapias = new org.jdesktop.swingx.JXTable();
        jLabel3 = new javax.swing.JLabel();
        bRemTerapia = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tablaMedicamentos = new org.jdesktop.swingx.JXTable();
        jLabel4 = new javax.swing.JLabel();
        bRemovMedicam = new javax.swing.JButton();
        bGuardarTrat = new javax.swing.JButton();
        medicamento_View_Add1 = new v.Medicamento_View_Add();
        botonAgregarMed = new javax.swing.JButton();
        PanelInformacion = new org.jdesktop.swingx.JXPanel();
        IconoInformacion = new javax.swing.JLabel();
        LInformacion = new javax.swing.JLabel();

        botonAgregarTer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/add24.png"))); // NOI18N
        botonAgregarTer.setText("Agregar");
        botonAgregarTer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarTerActionPerformed(evt);
            }
        });

        tablaTerapias.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tablaTerapias);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setText("Nuevas Terapias Asignadas");

        bRemTerapia.setFont(new java.awt.Font("Tahoma", 1, 18));
        bRemTerapia.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/remove24.png"))); // NOI18N
        bRemTerapia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bRemTerapiaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bRemTerapia))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 463, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3))
                    .addComponent(bRemTerapia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(terapia_View_Add1, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(99, 99, 99)
                .addComponent(botonAgregarTer, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 520, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(terapia_View_Add1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonAgregarTer)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tablaMedicamentos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane4.setViewportView(tablaMedicamentos);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Nuevos Medicamentos Asignados");

        bRemovMedicam.setFont(new java.awt.Font("Tahoma", 1, 18));
        bRemovMedicam.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/remove24.png"))); // NOI18N
        bRemovMedicam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bRemovMedicamActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 471, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bRemovMedicam))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4))
                    .addComponent(bRemovMedicam))
                .addGap(17, 17, 17)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bGuardarTrat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/guardar32.png"))); // NOI18N
        bGuardarTrat.setText("Guardar");
        bGuardarTrat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarTratActionPerformed(evt);
            }
        });

        botonAgregarMed.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/add24.png"))); // NOI18N
        botonAgregarMed.setText("Agregar");
        botonAgregarMed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarMedActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(medicamento_View_Add1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                                        .addComponent(botonAgregarMed, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(15, 15, 15)))
                                .addGap(18, 18, 18)
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(386, 386, 386)
                        .addComponent(bGuardarTrat)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, 0, 234, Short.MAX_VALUE)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(medicamento_View_Add1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonAgregarMed)))
                .addGap(18, 18, 18)
                .addComponent(bGuardarTrat)
                .addContainerGap())
        );

        PanelInformacion.setBackground(java.awt.SystemColor.activeCaption);
        PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/informacion64.png"))); // NOI18N

        LInformacion.setFont(new java.awt.Font("Helvetica Neue", 0, 14));
        LInformacion.setForeground(new java.awt.Color(255, 102, 0));
        LInformacion.setText("Aqui Texto - Informacion | Validacion | Ayuda y demas ");

        javax.swing.GroupLayout PanelInformacionLayout = new javax.swing.GroupLayout(PanelInformacion);
        PanelInformacion.setLayout(PanelInformacionLayout);
        PanelInformacionLayout.setHorizontalGroup(
            PanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelInformacionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(IconoInformacion)
                .addGap(18, 18, 18)
                .addComponent(LInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
                .addContainerGap())
        );
        PanelInformacionLayout.setVerticalGroup(
            PanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelInformacionLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(PanelInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LInformacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                    .addComponent(IconoInformacion, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(42, 42, 42))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(PanelInformacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PanelInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    
private void bGuardarTratActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarTratActionPerformed
    copiarElem(elemLocales, elemRecibidos);
    if(null != listener)
        listener.ejecutarAccion();
}//GEN-LAST:event_bGuardarTratActionPerformed

private void botonAgregarTerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarTerActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_botonAgregarTerActionPerformed

private void botonAgregarMedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarMedActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_botonAgregarMedActionPerformed

private void bRemTerapiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bRemTerapiaActionPerformed
        int selectedRow = tablaTerapias.getSelectedRow();
        if(selectedRow > -1){
            TerapiaDiscapacidad terapiaBorrar = terapiasTabla.get(selectedRow);
            if(elemLocales.nuevasTer.remove(terapiaBorrar)){
                System.out.println("No");
                DefaultTableModel model = ((DefaultTableModel) tablaTerapias.getModel());
                model.removeRow(selectedRow);
            }
        }
    
}//GEN-LAST:event_bRemTerapiaActionPerformed

private void bRemovMedicamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bRemovMedicamActionPerformed
// TODO add your handling code here:
    int selectedRow = tablaMedicamentos.getSelectedRow();
    if (selectedRow > -1) {
        MedicamentoDiscapacidad medicBorrar = medicamentosTabla.get(selectedRow);
        if (elemLocales.nuevosMedic.remove(medicBorrar)) {
            DefaultTableModel model = ((DefaultTableModel) tablaMedicamentos.getModel());
            model.removeRow(selectedRow);
        }
    }
}//GEN-LAST:event_bRemovMedicamActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel IconoInformacion;
    private javax.swing.JLabel LInformacion;
    private org.jdesktop.swingx.JXPanel PanelInformacion;
    private javax.swing.JButton bGuardarTrat;
    private javax.swing.JButton bRemTerapia;
    private javax.swing.JButton bRemovMedicam;
    private javax.swing.JButton botonAgregarMed;
    private javax.swing.JButton botonAgregarTer;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private v.Medicamento_View_Add medicamento_View_Add1;
    private org.jdesktop.swingx.JXTable tablaMedicamentos;
    private org.jdesktop.swingx.JXTable tablaTerapias;
    private v.Terapia_View_Add terapia_View_Add1;
    // End of variables declaration//GEN-END:variables

    
    private void setListeners() {        
        botonAgregarTer.addActionListener(agregarTerapiaListener);
        botonAgregarMed.addActionListener(agregarMedicamentoListener);
        
    }
    private void setTerapiaModel(Set<TerapiaDiscapacidad> terapias){
        int size = terapias.size();
        Object[][] datos = new Object[size][columnTerapia.length];
        terapiasTabla = new HashMap<Integer, TerapiaDiscapacidad>();
        
        TerapiaDiscapacidad[] toArray = terapias.toArray(new TerapiaDiscapacidad[size]);
        
        for(int i = 0; i < toArray.length; i++){
            final TerapiaDiscapacidad terapia = toArray[i];
            terapiasTabla.put(i, terapia);
            datos[i][0] = cbx.getValueTerapia(terapia.getIdTerapia().toString());
            System.out.println("Terapia ac: " + terapia.getIdTerapia().toString());
            datos[i][1] = String.format("Cada %s %s", terapia.getIntensidad(), 
                    cbx.getValueMedidas(terapia.getIntensidadMedidaTiempo().toString()));
//            datos[i][2] = cbx.getValueMedidas(terapia.getIntensidadMedidaTiempo().toString());
//            System.out.println("Intensidad medida: " + terapia.getIntensidadMedidaTiempo().toString());
            datos[i][2] = terapia.getCantidad();
            datos[i][3] = terapia.getFechaInicio();
        }
        
        
       terapiaModel = new DefaultTableModel(datos, columnTerapia); 
       tablaTerapias.setModel(terapiaModel);
    }
    
    private void setMedicamentosModel(Set<MedicamentoDiscapacidad> medicamentos) {
        int size = medicamentos.size();
        Object[][] datos = new Object[size][columnMedic.length];

        MedicamentoDiscapacidad[] toArray = 
                medicamentos.toArray(new MedicamentoDiscapacidad[size]);
        
        medicamentosTabla = new HashMap<Integer, MedicamentoDiscapacidad>();
        
        
        for (int i = 0; i < toArray.length; i++) {
            final MedicamentoDiscapacidad medicamento = toArray[i];
            
            medicamentosTabla.put(i, medicamento);
            
            datos[i][0] = cbx.getValueMedicamentos(medicamento.getIdMedicamento().toString());
            datos[i][1] = String.format("Cada %s %s", medicamento.getDosis(),
                    cbx.getValueMedidas(medicamento.getDosisMedidaTiempo().toString()));
//            datos[i][2] = cbx.getValueMedidas(medicamento.getUsoMedidaTiempo().toString());
            datos[i][2] = String.format("Cada %s %s", medicamento.getUso(),
                    cbx.getValueMedidas(medicamento.getUsoMedidaTiempo().toString()));
//            datos[i][3] = cbx.getValueMedidas(medicamento.getUsoMedidaTiempo().toString());
            datos[i][3] = medicamento.getFechaInicio();
        }

        medicamentoModel = new DefaultTableModel(datos, columnMedic);
        tablaMedicamentos.setModel(medicamentoModel);
    }
    
    private ActionListener agregarTerapiaListener = new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                TerapiaDiscapacidad info = terapiaPanel.getInfo();
                info.setFechaInicio(new Date());
                elemLocales.nuevasTer.add(info);
                setTerapiaModel(elemLocales.nuevasTer);
                terapiaPanel.resetearComponentes();
            } catch (Exception ex) {
                informarUsuario(String.format(
                        "error[Al agregar terapia] %s", ex.getMessage()));
                Logger.getLogger(NuevasTerMed_UI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    };
    
    private ActionListener agregarMedicamentoListener = new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                MedicamentoDiscapacidad info = medicamentoPanel.getInfo();
                info.setFechaInicio(new Date());
                elemLocales.nuevosMedic.add(info);
                setMedicamentosModel(elemLocales.nuevosMedic);
                medicamentoPanel.resetearComponentes();
            } catch (Exception ex) {
                informarUsuario(String.format(
                        "error[Al agregar medicamento] %s", ex.getMessage()));
                Logger.getLogger(NuevasTerMed_UI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    };

    private void setComponents() {
        terapiaPanel = terapia_View_Add1;
        
        medicamentoPanel = medicamento_View_Add1;
    }

    private void copiarElem(SetTerapiasMedicamentos source, SetTerapiasMedicamentos dest) {
        dest.nuevasTer.clear();
        dest.nuevosMedic.clear();
        
        for(TerapiaDiscapacidad nuevaTerapia: source.nuevasTer){
            dest.nuevasTer.add(nuevaTerapia);
        }
        for(MedicamentoDiscapacidad nuevoMed: source.nuevosMedic){
            dest.nuevosMedic.add(nuevoMed);
        }
    }
    
    public void setToolTip(String modo, String txt) {
        String rutaImg = "/core/img/";

        if (modo.equals("help")) {
            IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImg + "help64.png")));
            PanelInformacion.setBackground(new java.awt.Color(189, 229, 248)); //rgb(189, 229, 248)
            PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(47, 119, 178))); //rgb(47, 119, 178)
            LInformacion.setForeground(new java.awt.Color(0, 82, 162)); //rgb(0, 82, 162)
        } else if (modo.equals("ok")) {
            IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImg + "ok64.png")));
            PanelInformacion.setBackground(new java.awt.Color(254, 239, 179)); //rgb(254, 239, 179)
            PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(159, 99, 52))); //rgb(159, 99, 52)
            LInformacion.setForeground(new java.awt.Color(159, 99, 52));
        } else if (modo.equals("error")) {
            IconoInformacion.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImg + "error64.png")));
            PanelInformacion.setBackground(new java.awt.Color(255, 186, 186)); //rgb(255, 186, 186)
            PanelInformacion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(222, 0, 12))); //rgb(222, 0, 12)
            LInformacion.setForeground(new java.awt.Color(222, 0, 12));
        }
        setMensaje(txt);
    }
    
    public void setMensaje(String msj) {
        LInformacion.setText(msj);
    }

    public void informarUsuario(String txt) {
        if (!txt.isEmpty()) {
            String modo = txt.substring(0, txt.indexOf("["));
            String mensajeHTML = String.format("<html><p><font size=\"8\">%s</font></p><p><font size=\"5\">%s</font></p></html>", txt.substring(txt.indexOf("[") + 1, txt.indexOf("]")), txt.substring(txt.lastIndexOf("]") + 1));
            setToolTip(modo, mensajeHTML);
        }
    }

    void addActionListener(Listener listener) {
        this.listener = listener;
    }
}
